// Make sure and use old Arduino IDE Software version 1.6.11 (for sure, it's what I use) or earlier (possibly). Latest version doesn't work. // Old versions can be downloaded here:  https://www.arduino.cc/en/Main/OldSoftwareReleases#previous // Also have to install an older version of Python 2.7.13 as per beginner instructions in 2. below. NOT latest Python version. Doesn't work. // Also need to load all the libraries listed at the top of the code into Arduino IDE. // // The following Nodemcu 12E (LoLin V3) code includes lines for Over the Air Programming, // LED control from web page, DS32331 Real Time Clock display, DHT22 temp and humidity display, DS18B20 temp display, // MCP23017 digital I/O expander with button input and LED output and 4 channel relay board // Relay power is 5 V so LoLin Nodemcu 12E has a VU output which is V USB and is 5 V // Analog input from photo resistor will be used to detect flame ON LED on gas furnace. // Most of these functions are used for gas furnace and water heater control currently using Arduino Uno. Ran out of memory with the Uno. Saves $60-$80 per month. $500+ per year. // To be replaced with this ESP8266. MCP23017 outputs are connected to a relay board for furnace and water heater control. // Code is cut and pasted from many sources especially examples from included library directories // // Screenshot of html web page coming from the board is here: //  https://sites.google.com/site/nodemcu12e/ // // Picture of setup and wiring is here: //  https://sites.google.com/site/nodemcu12e/ // // Nodemcu 12E board spans across the edges of two 17X10 protoboards so lots of pin locations are available plus isolated pin area // for mounting Real Time Clock DS3231, DHT22 temp and humidity, input button and photoresistor and DS18B20 connections. // Third board is for MCP23017. All are mounted on a piece of plastic. // // For beginners I followed these videos and website instructions in order. // //  1. Getting started. You have to add esp8266 to list of boards in Arduino IDE. //       Put a 200 ohm resistor in series with the LED NOT directly on output as shown. //         https://m.youtube.com/watch?v=NEo1WsT5T7s // //  2. Wireless Over The Air (OTA) programming setup. Serial monitor won't work after this. //         https://m.youtube.com/watch?v=ZVA1pV6WUQg                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          // //  3. Control LED from a web page. Need to learn some html //         http://internetofthinking.blogspot.ca/2015/12/control-led-from-webserver-using.html // //  4. To create a web page to store images and program backup: //           http://youtu.be/vgpbGjXRObE #include        //*** Enables OTA programming. 1 of 3 lines WiFiServer server(80);         //Used for WiFi Server #include         //Real Time Clock library on I2C for DS3231. pin D1 is SCL, pin D2 is SDA #include           //Used for DS18B20 temp sensors https://datasheets.maximintegrated.com/en/ds/DS18B20.pdf #include //Used for DS18B20 temp sensors. Run Simple DS18B20 from DallasTemperature first to find sensor addresses.                                //Run Example Simple.pde from DallasTemperature first to find sensor addresses. #include              //I2C library Used for Real Time Clock and MCP23017 I/O expander. Same two wires. #include         //RTC library #include "Adafruit_MCP23017.h" //MCP23017 I/O expander see library example. Note: 10K resistor VDD pin 9 to pin 18.                                // Note: pin 9 VDD=3.3V power pin 10 VSS=Ground                                //pin 12 is SCL, pin 13 is SDA pins 15,16,17 grounded to set chip address to 0                                //MCP23017 datasheet: https://drive.google.com/file/d/0ByB7Piqn39AAUS1uU2RVRGctZVk/view?usp=sharing #include               //Used for DHT22 temp and humidity measurement. Note I am using Adafruit library version 1.0.0 NOT newer versions. #define DHT1PIN D5             //What pin temp sensor 1 connected to D5 = 14 #define DHTTYPE DHT22          //DHT 22 temp sensor  (AM2302) DHT dht1(DHT1PIN, DHTTYPE, 20); //NOTE!!! 20 is needed to adjust timing for higher speed ESP8266. See DHTtester.ino example in 1.0.0 library. #define ONE_WIRE_BUS D3         //Define pin the one wire bus is on Adafruit_MCP23017 mcp;          // MCP23017 I/O expander gives 16 more digital I/O to board using I2C RtcDS3231 Rtc(Wire);   // Real Time clock int yvalue, rvalue, input4, analoginput, counter, wkday, allowhi, offtimewh; // int autowh; // water heater auto mode int RL1FURNACEOFF = 8; // relay 1 furnace OFF output 8 on MCP23017 int RL2FURNACELO = 9;  // relay 2 furnace LOW output 9 on MCP23017 int RL4HEATEROFF = 11; // relay 4 water heater on or off relay ON for heater OFF int HeaterOFF; // water heater status bit int lastSecond = -1; // set last second to impossible number so it prints right away then every second int currentmillis = 0; int previousmillis = 0; String request, timedate, Month, Day, Hour, Minute, Second, dow; String insidetemp, humidity, furnaceLED, basementtemp, outsidetemp, tempdata; float t1, temp1, t2, temp2, h1, prevh1, prevt1, alertsent; // Furnace Variables     int furnaceONvalue = 0;        // value read from the furnace on sensor = analog input     int off_flag; // furnace off flag     int onoffval = 0;     int furnaceONtime = 0;     int furnaceONrecord = 0;     int offtime, furnacelo;     int furnaceOFF; // furnace status bit     int furnaceOFFtime = 0;     int furnaceOFFrecord = 0;     int furnaceOFFflag = 0;     int serialreport = 0;     int ONpercent = 0;     float degreesC, temp1raw, temp2raw, IATvalue;      float lowsetpoint = 19.0;     int IATaverage;     int recordbit = 1.0;     int seconds, timeNOW, timeLAst;     int ONhour =0;     int ONtotal = 0;     String StrfurnaceONtime, StrfurnaceONrecord, StrfurnaceOFFtime, StrfurnaceOFFrecord, StrONtotal;     //record ONpercent every hour     int ONpct0; int ONpct1; int ONpct2; int ONpct3; int ONpct4; int ONpct5; int ONpct6; int ONpct7; int ONpct8; int ONpct9;     int ONpct10; int ONpct11; int ONpct12; int ONpct13; int ONpct14; int ONpct15; int ONpct16; int ONpct17; int ONpct18; int ONpct19;     int ONpct20; int ONpct21; int ONpct22; int ONpct23;         int ONtotal0; int ONtotal1; int ONtotal2; int ONtotal3; int ONtotal4; int ONtotal5; int ONtotal6; int ONtotal7; int ONtotal8; int ONtotal9;     int ONtotal10; int ONtotal11; int ONtotal12; int ONtotal13; int ONtotal14; int ONtotal15; int ONtotal16; int ONtotal17; int ONtotal18; int ONtotal19;     int ONtotal20; int ONtotal21; int ONtotal22; int ONtotal23;         int ONhour0; int ONhour1; int ONhour2; int ONhour3; int ONhour4; int ONhour5; int ONhour6; int ONhour7; int ONhour8; int ONhour9;     int ONhour10; int ONhour11; int ONhour12; int ONhour13; int ONhour14; int ONhour15; int ONhour16; int ONhour17; int ONhour18; int ONhour19;     int ONhour20; int ONhour21; int ONhour22; int ONhour23;     // End of Furnace Variables OneWire oneWire(ONE_WIRE_BUS);        //Used for DS18B20 temp sensors DallasTemperature sensors(&oneWire);  //Used for DS18B20 temp sensors DeviceAddress Sens1, Sens2;           //Used for DS18B20 temp sensors // Alert Setup - Send furnace seconds=gas consumption to Google spreadsheet automatically const char *host = "maker.ifttt.com";  const char *privateKey = "zzzzzzzzzzzzzzzzzz"; // Get zzz code from ifttt.com String  url = "/trigger/Home_Data/with/key/zzzzzzzzzzzzzzzzz";// Get zzz code from ifttt.com // End of Alert Setup void setup() {    ArduinoOTA.begin(); //*** Enables OTA programming. 2 of 3 lines    server.begin();    dht1.begin();    mcp.begin();      // use default address 0 on MCP23017 I/O expander    pinMode(D6, OUTPUT);     // Initialize D6 pin as an output YELLOW LED on Nodemcu 12E board    pinMode(D7, OUTPUT);     // Initialize D7 pin as an output RED LED    on Nodemcu 12E board    mcp.pinMode(4, INPUT); // test mcp input with button. Grounds pin for input    mcp.pullUp(4, HIGH);  // turn on a 100K pullup internally. input switch grounds LOW for input    mcp.pinMode(5, OUTPUT);     // Initialize mcp 5 pin as an output GREEN LED   on MCP23017    mcp.pinMode(6, OUTPUT);     // Initialize mcp 6 pin as an output YELLOW LED  on MCP23017    mcp.pinMode(7, OUTPUT);     // Initialize mcp 7 pin as an output RED LED     on MCP23017    mcp.pinMode(RL1FURNACEOFF, OUTPUT);    // Initialize mcp 8 pin as furnace OFF output Relay 1 on MCP23017    mcp.pinMode(RL2FURNACELO, OUTPUT);     // Initialize mcp 9 pin as furnace LOW output Relay 2 on MCP23017    mcp.pinMode(10, OUTPUT);    // Initialize mcp 10 pin as an output Relay 3 on MCP23017 - not used    mcp.pinMode(RL4HEATEROFF, OUTPUT);    // Initialize mcp 11 pin as water heater output Relay 4 on MCP23017       mcp.digitalWrite(8, HIGH);  // Since relays are active LOW write High to outputs initially.    mcp.digitalWrite(9, HIGH);  // Since relays are active LOW write High to outputs initially.    mcp.digitalWrite(10, HIGH); // Since relays are active LOW write High to outputs initially.    mcp.digitalWrite(11, HIGH); // Since relays are active LOW write High to outputs initially.      Rtc.Begin();     //Starts I2C         // Start up the DS18B20 library and set temp resolution 11 bits equals .125C        sensors.begin();    sensors.getAddress(Sens1, 0);    sensors.setResolution(Sens1, 11);    sensors.getAddress(Sens2, 1);    sensors.setResolution(Sens2, 11);     //  Uncomment to set RTC if required - after setting clock make sure and upload commented version again or time will be reset on reboot //    RtcDateTime t = RtcDateTime(17, 6, 30, 19, 13, 0); //set date and time NO leading zeroes (yr mo day Hour min sec) //    Rtc.SetDateTime(t); //configure the RTC with object // send about 20 secs before actual time.gov time to allow for compile          } int  autowh = 1; // default for water heater is auto mode (off on weekdays) void loop() {   ArduinoOTA.handle();     //*** Enables OTA programming. 3 of 3 lines     mcp.digitalWrite(5, mcp.digitalRead(4)); // Test input button on MCP23017. Mirror inverted state on mcp output 6    //*************Analog Input read******************************************************     analoginput = analogRead(0); //Check!! Nodemcu 12E is digital 0 to 1024 for input 0 to 3.3V NOT 0 to 1.0V on pin A0.     furnaceONvalue = analoginput; // furnace program uses this variable for analog input of furnace LED ON //*******Get Date and Time*************************************************   RtcDateTime t = Rtc.GetDateTime();    //get the time from the RTC   char str[15];   //declare a string as an array of chars   sprintf(str, "%d/%d/%d %d:%d:%d",     //%d allows to print an integer to the string           t.Year(),   //get year method           t.Month(),  //get month method           t.Day(),    //get day method           t.Hour(),   //get Hour method           t.Minute(), //get Minute method           t.Second()  //get Second method             ); //********End Get Date and Time*********************************************** //*********Water Heater Logic************************************************* if((t.DayOfWeek() >= 1) && (t.DayOfWeek() <=5)){  //check if it's a weekday              wkday = 1;            }            else {              wkday = 0;            }                 if(((t.Hour() == 5) && (t.Minute() >= 50)) //check if between 5:50 and 23:50             || (t.Hour() >= 6) && (t.Hour() < 23)             || ((t.Hour() == 23) && (t.Minute() <= 50))){              offtimewh = 1;            }            else {              offtimewh = 0;            }                        if ((wkday == 1) && (offtimewh == 1) && (autowh == 1)){ //if weekday and offtime and auto mode turn off water heater                  mcp.digitalWrite(RL4HEATEROFF, LOW); // LOW to turn relay ON            HeaterOFF = 1;        }        else {            mcp.digitalWrite(RL4HEATEROFF, HIGH);            HeaterOFF = 0;        } //*********End Water Heater Logic**************************************************** //********Read temp and humidity from DHT22 and DS18B20s*****************************            sensors.requestTemperatures(); // Send the command to get temperatures from DS18B20s            // Reading temperature or humidity takes about 250 milliSeconds! // Sensor readings may also be up to 2 Seconds 'old' (its a very slow sensor)            float h1 = dht1.readHumidity();           //DHT1 humidity    delay(150);        float t1 = dht1.readTemperature();        //DHT1 temp    delay(150);       if ((h1 > 100) || (t1 < 15.0) || (t1 > 32.0)) {// Read error checking. If error set to previous reading.       h1 = prevh1;                 // Was returning double values sometimes.       t1 = prevt1;      }           prevh1=h1;      prevt1=t1;            // Check if any reads failed and exit early (to try again).      // if (isnan(h1) || isnan(t1)) {      //   Serial.println("Failed to read from DHT sensor!");      //   return;      //   }               temp1raw = sensors.getTempCByIndex(0); //DSB1820 temp1       if ((temp1raw > -50.0) && (temp1raw < 50.0)) temp1 = temp1raw; // error checking           temp2raw = sensors.getTempCByIndex(1); //DSB1820 temp2       if ((temp2raw > -50.0) && (temp2raw < 50.0)) temp2 = temp2raw; // error checking       //********End read temp and humidity**************************************** //*****Run following every second***********************************************    //********Furnace Logic*********************************************************  // Furnace OFF when 1.5 degrees C lower than thermostat               if(((furnaceOFFtime == 5) || (furnaceOFFtime == 6)) && (furnaceONrecord > 60)) {furnaceOFFflag = 1;}             // Set furnaceOFFflag ON just after furnace turns off        if((furnaceOFFtime == 60) && (t1 > 17.5))  {lowsetpoint = t1 - 1.5;} // Calculate lowsetpoint where furnace turns back ON if temp > 17.5C        if((t1 < lowsetpoint) || (furnaceOFFtime > 14400) || (t1 < 16.1)) {furnaceOFFflag = 0;}         if((t.Hour() == 5) && (t.Minute() > 30)  ) {furnaceOFFflag = 0;}        if((t.Hour() == 5) && (t.Minute() > 30)  ) {lowsetpoint = 19.0;}          // Furnace on/off            if(((t.Hour() == 14) && (t.Minute() > 55)            || ((t.Hour() == 23) && (t.Minute() < 30)            || ((t.Hour() == 3)  && (t.Minute() < 30)            || (furnaceOFFflag == 1)            )))){              mcp.digitalWrite(RL1FURNACEOFF, LOW); // relay ON active LOW              furnaceOFF = 1;            }            else {              mcp.digitalWrite(RL1FURNACEOFF, HIGH);              furnaceOFF = 0;            }              // Allow Furnace HI if outside temp < -7C and at 5 a.m. and 2 p.m. weekdays removed 2 p.m. (14) for summer changed to 1 a.m.            if(temp2 < -7) {allowhi = 1;} // allow furnace hi if temp below -7C            if(temp2 > -5) {allowhi = 0;} // turn off allowhi if temp higher than -5 so some hysteresis            if(((t.Hour() == 5)  && (t.Minute() < 59)            || (((t.Hour() == 1) && (t.Minute() < 59)            && (allowhi == 1)             && t.DayOfWeek() == 1)))){              mcp.digitalWrite(RL2FURNACELO, HIGH ); //HIGH = ALLOW HI OUTPUT (relay OFF)                     furnacelo = 0;             }             else {              mcp.digitalWrite(RL2FURNACELO, LOW);  //LOW = FORCE LOW OUTPUT (relay ON active LOW)               furnacelo = 1;            }         // Furnace record ON and OFF times     if(lastSecond != t.Second()) {        lastSecond = t.Second();                    if((furnaceONvalue >= 150) && (furnaceONtime < 99999)) {furnaceONtime = furnaceONtime +1;}        if(furnaceONvalue >= 150) {ONtotal = ONtotal +1;}        if((furnaceONvalue < 150) && (furnaceOFFtime < 99999)) {furnaceOFFtime = furnaceOFFtime +1;}        }                if((furnaceONtime > 2) && (furnaceONtime < 20))  {furnaceOFFrecord = furnaceOFFtime;}        if((furnaceONtime > 20) && (furnaceONtime < 40)) {furnaceOFFtime = 0;}        if((furnaceOFFtime > 2) && (furnaceOFFtime < 20) && (furnaceONtime > 120)) {furnaceONrecord = furnaceONtime;}        if((furnaceOFFtime > 20) && (furnaceOFFtime <40))  {furnaceONtime = 0;}                if (furnaceONrecord > 10)  ONpercent = 100 * furnaceONrecord / (furnaceONrecord + furnaceOFFrecord);           //reset ONpercent if furnace off for 3600 secs or 1 Hour       if (furnaceOFFtime >= 3600){           ONpercent = 0;}             // zero counter at top of hour        if ((t.Minute() > 55) ) recordbit = 1; //actions set to a second are unreliable set recordbit at 55 mins+                          // Record ONpercent every Hour          if ((recordbit == 1) && (t.Hour() == 0) && (t.Minute() == 0) ){ //record at earliest time in first minute             recordbit = 0;           ONtotal0 = ONtotal;           ONhour0 = ONtotal - ONtotal23;           ONpct0 = 100 * ONhour0 / 3600;}        if ((recordbit == 1) && (t.Hour() == 1) && (t.Minute() == 0) ){           recordbit = 0;           ONtotal1 = ONtotal;           ONhour1 = ONtotal - ONtotal0;           ONpct1 = 100 * ONhour1 / 3600;}        if ((recordbit == 1) && (t.Hour() == 2) && (t.Minute() == 0) ){           recordbit = 0;           ONtotal2 = ONtotal;           ONhour2 = ONtotal - ONtotal1;           ONpct2 = 100 * ONhour2 / 3600;}        if ((recordbit == 1) && (t.Hour() == 3) && (t.Minute() == 0) ){           recordbit = 0;           ONtotal3 = ONtotal;           ONhour3 = ONtotal - ONtotal2;           ONpct3 = 100 * ONhour3 / 3600;}        if ((recordbit == 1) && (t.Hour() == 4) && (t.Minute() == 0) ){           recordbit = 0;           ONtotal4 = ONtotal;           ONhour4 = ONtotal - ONtotal3;           ONpct4 = 100 * ONhour4 / 3600;}        if ((recordbit == 1) && (t.Hour() == 5) && (t.Minute() == 0) ){           recordbit = 0;           ONtotal5 = ONtotal;           ONhour5 = ONtotal - ONtotal4;           ONpct5 = 100 * ONhour5 / 3600;}        if ((recordbit == 1) && (t.Hour() == 6) && (t.Minute() == 0) ){           recordbit = 0;           ONtotal6 = ONtotal;           ONhour6 = ONtotal - ONtotal5;           ONpct6 = 100 * ONhour6 / 3600;}        if ((recordbit == 1) && (t.Hour() == 7) && (t.Minute() == 0) ){           recordbit = 0;           ONtotal7 = ONtotal;           ONhour7 = ONtotal - ONtotal6;           ONpct7 = 100 * ONhour7 / 3600;}        if ((recordbit == 1) && (t.Hour() == 8) && (t.Minute() == 0) ){           recordbit = 0;           ONtotal8 = ONtotal;           ONhour8 = ONtotal - ONtotal7;           ONpct8 = 100 * ONhour8 / 3600;}        if ((recordbit == 1) && (t.Hour() == 9) && (t.Minute() == 0) ){           recordbit = 0;           ONtotal9 = ONtotal;           ONhour9 = ONtotal - ONtotal8;           ONtotal = 0;                   // reset ONtotal to zero at 9 a.m. after recording           ONpct9 = 100 * ONhour9 / 3600;}        if ((recordbit == 1) && (t.Hour() == 10) && (t.Minute() == 0) ){           recordbit = 0;           ONtotal10 = ONtotal;           ONhour10 = ONtotal;           ONpct10 = 100 * ONhour10 / 3600;}        if ((recordbit == 1) && (t.Hour() == 11) && (t.Minute() == 0)){           recordbit = 0;           ONtotal11 = ONtotal;           ONhour11 = ONtotal - ONtotal10;           ONpct11 = 100 * ONhour11 / 3600;}        if ((recordbit == 1) && (t.Hour() == 12) && (t.Minute() == 0) ){           recordbit = 0;           ONtotal12 = ONtotal;           ONhour12 = ONtotal - ONtotal11;           ONpct12 = 100 * ONhour12 / 3600;}        if ((recordbit == 1) && (t.Hour() == 13) && (t.Minute() == 0) ){           recordbit = 0;           ONtotal13 = ONtotal;           ONhour13 = ONtotal - ONtotal12;           ONpct13 = 100 * ONhour13 / 3600;}        if ((recordbit == 1) && (t.Hour() == 14) && (t.Minute() == 0) ){           recordbit = 0;           ONtotal14 = ONtotal;           ONhour14 = ONtotal - ONtotal13;           ONpct14 = 100 * ONhour14 / 3600;}        if ((recordbit == 1) && (t.Hour() == 15) && (t.Minute() == 0) ){           recordbit = 0;           ONtotal15 = ONtotal;           ONhour15 = ONtotal - ONtotal14;           ONpct15 = 100 * ONhour15 / 3600;}        if ((recordbit == 1) && (t.Hour() == 16) && (t.Minute() == 0) ){           recordbit = 0;           ONtotal16 = ONtotal;           ONhour16 = ONtotal - ONtotal15;           ONpct16 = 100 * ONhour16 / 3600;}        if ((recordbit == 1) && (t.Hour() == 17) && (t.Minute() == 0) ){           recordbit = 0;           ONtotal17 = ONtotal;           ONhour17 = ONtotal - ONtotal16;           ONpct17 = 100 * ONhour17 / 3600;}        if ((recordbit == 1) && (t.Hour() == 18) && (t.Minute() == 0) ){           recordbit = 0;           ONtotal18 = ONtotal;           ONhour18 = ONtotal - ONtotal17;           ONpct18 = 100 * ONhour18 / 3600;}        if ((recordbit == 1) && (t.Hour() == 19) && (t.Minute() == 0) ){           recordbit = 0;           ONtotal19 = ONtotal;           ONhour19 = ONtotal - ONtotal18;           ONpct19 = 100 * ONhour19 / 3600;}        if ((recordbit == 1) && (t.Hour() == 20) && (t.Minute() == 0)){           recordbit = 0;           ONtotal20 = ONtotal;           ONhour20 = ONtotal - ONtotal19;           ONpct20 = 100 * ONhour20 / 3600;}        if ((recordbit == 1) && (t.Hour() == 21) && (t.Minute() == 0) ){           recordbit = 0;           ONtotal21 = ONtotal;           ONhour21 = ONtotal - ONtotal20;           ONpct21 = 100 * ONhour21 / 3600;}        if ((recordbit == 1) && (t.Hour() == 22) && (t.Minute() == 0) ){           recordbit = 0;           ONtotal22 = ONtotal;           ONhour22 = ONtotal - ONtotal21;           ONpct22 = 100 * ONhour22 / 3600;}        if ((recordbit == 1) && (t.Hour() == 23) && (t.Minute() == 0) ){           recordbit = 0;           ONtotal23 = ONtotal;           ONhour23 = ONtotal - ONtotal22;           ONpct23 = 100 * ONhour23 / 3600;}             //reset ONpercent if furnace off for 3600 secs or 1 Hour       if (furnaceOFFtime >= 3600){           ONpercent = 0;}          //********End Furnace Logic***************************************************** //********Send Text Alert******************************************************* // Send furnace seconds=gas consumption to Google spreadsheet automatically // Extra data to send can send up to 3 values total ON seconds, inside temp, outside temp String v1 = String(ONtotal9); String v2 = String(t1,1); String v3 = String(temp2,1); // Convert float value to a string named sv3 //char sv3[16];  //dtostrf(v3,8, 2, sv3); String df1 = "{\"value1\":"; String df2 = "\"value2\":"; String df3 = "\"value3\":"; // Create body data string String IFTTT_POST_DATA = df1 + "\"" + v1 + "\"" + "," + df2 + "\"" + v2 + "\"" + "," + df3 + "\"" + v3 + "\"" + "}" ; // Determine body data string size String IFTTT_POST_DATA_SIZE = String(IFTTT_POST_DATA.length()); // Send HTTP POST Request to IFTTT  if ((alertsent == 0) && (t.Hour() == 9) && (t.Minute() == 1) )         {                 WiFiClient client;       const int httpPort = 80;       client.connect(host, httpPort);       client.print(String("POST ") + url + " HTTP/1.1\r\n"     + "Host: " + host + "\r\n"     + "Connection: close\r\n"     + "Content-Type: application/json\r\n"     + "Content-Length: " + IFTTT_POST_DATA_SIZE + "\r\n"     + "\r\n"     + IFTTT_POST_DATA + "\r\n");     alertsent=1; // alertsent bit set so only sends once               }        if (t.Hour() == 10) alertsent = 0;    //********End Send Text Alert************************************************ //*******WiFi detect client and record input******************************** // Check if a client has connected   WiFiClient client = server.available();   if (!client) {     return;   }   // Read the first line of the request       request = client.readStringUntil('\r');       client.flush(); //*******End of WiFi detect client and record input******************************** //*************Actions on button click. Buttons defined below.************************         if (request.indexOf("/YELLOW_LED=ON") != -1)  {// Input from screen. No spaces in name.       digitalWrite(D6, HIGH);       mcp.digitalWrite(6, HIGH);        yvalue = HIGH;   }   if (request.indexOf("/YELLOW_LED=OFF") != -1)  {// Input from screen. No spaces in name.       digitalWrite(D6, LOW);       mcp.digitalWrite(6, LOW);       yvalue = LOW;   } // Match the request for Red LED     if (request.indexOf("/RED_LED=ON") != -1)  {// Input from screen. No spaces in name.     digitalWrite(D7, HIGH);     mcp.digitalWrite(7, HIGH);     rvalue = HIGH;   }   if (request.indexOf("/RED_LED=OFF") != -1)  {// Input from screen. No spaces in name.     digitalWrite(D7, LOW);     mcp.digitalWrite(7, LOW);     rvalue = LOW;      }   if (request.indexOf("/CLR_OFF_FLAG") != -1)  {// Input from screen. No spaces in name. Furnace off flag      furnaceOFFflag = 0;      }        if (request.indexOf("/AUTO_ON") != -1)  {// Input from screen. No spaces in name. Water heater auto mode      autowh = 1;      }    if (request.indexOf("/AUTO_OFF") != -1)  {// Input from screen. No spaces in name. Water heater auto mode      autowh = 0;      }         request.indexOf("/HOME");  // Go to Home page after LEDs set.        //*******End of button actions****************************************************** //****** Return the response in HTML on web page************************************   client.println("HTTP/1.1 200 OK");   client.println("Content-Type: text/html");   client.println(""); //  do not forget this one   client.println("");   client.println( // start code html with this. Have to add quotes before and after. Delete most html quotes in line.     ""         ""           "Home Automation"  //           "" // Auto refresh every 60 secs. Issues?       ""        ""                    ""     "" //Use monospace font to make columns of text and numbers line up     "

"); // large font applies between

and

below  //*********End HTML page start of defintion*****************************************    //*****Background Images** Use background= for all your jpgs. HTML position does not work. Add big white spc in jpg to right and below to stop repeats.  client.println(""); //*****End of background images    //*********Print Date and Time add leading zeroes***********************************         Hour = String(t.Hour()); // integers like t.Hour() are used for comparisons and control. Change to string for display and add leading zeroes     if (t.Hour() <= 9) Hour = "0" + Hour;  // adjust for 0-9       Minute = String(t.Minute());     if (t.Minute() <= 9) Minute = "0" + Minute;  // adjust for 0-9       Second = String(t.Second());     if (t.Second() <= 9) Second = "0" + Second;  // adjust for 0-9       if (t.DayOfWeek() == 0) dow = " Sun"; // t.DayOfWeek() calculated from rest of date not from DS3231     if (t.DayOfWeek() == 1) dow = " Mon";     if (t.DayOfWeek() == 2) dow = " Tue";     if (t.DayOfWeek() == 3) dow = " Wed";     if (t.DayOfWeek() == 4) dow = " Thu";     if (t.DayOfWeek() == 5) dow = " Fri";     if (t.DayOfWeek() == 6) dow = " Sat";     Month = String(t.Month());     Day = String(t.Day());        if (t.Month() <= 9) Month = "0" + Month;  // adjust for 0-9 in month     if (t.Day() <= 9) Day = "0" + Day;  // adjust for 0-9 in day        timedate = String(t.Year())+ "/" + Month + "/" + Day + " " + Hour + ":" + Minute + ":" + Second ; // create string for display with one client.println       client.println(timedate);     client.println(" "); // add spaces     client.println(dow); // print day of week     client.println(" "); // add spaces        //*********End Print Date and Time******************************************** //*********Button Style defintion CSS******************************************************************     client.println(  //html output. Put quotes around html code. Don't have to client.println every line     "" //*****End Button Style Definition************************************************************************************************ //******Buttons Definitions************************************************************************************************     "
"     ""   // Yellow LED ON button definition. No spaces     " " // horizontal space between buttons     "" //Yellow LED OFF button definition. No spaces     " "     ""      // Red LED ON button definition. No spaces     " " // horizontal space between buttons     ""    //Red LED OFF button definition. No spaces     " " // horizontal space between buttons     ""); //Home button definition. No spaces             //  client.print("   "); // add spaces   //client.println(   //    "      "); // add spaces          //*****End Button Definition************************************************************************************************ //*****send LED status pics*************************************************************************************************          if (digitalRead(D6) == 1) yvalue = 1;     if (digitalRead(D6) == 0) yvalue = 0;     if (digitalRead(D7) == 1) rvalue = 1;     if (digitalRead(D7) == 0) rvalue = 0;          if ((yvalue == HIGH) && (rvalue == HIGH)){       client.println("");       client.println("
");     }     if ((yvalue == LOW) && (rvalue == LOW)){       client.println("");       client.println("
");     }     if ((yvalue == HIGH) && (rvalue == LOW)){       client.println("");       client.println("
");     }     if ((yvalue == LOW) && (rvalue == HIGH)){       client.println("");       client.println(" ");           }       client.println("
");       client.println("
");       client.println(""); // internet date and time display //*****end LED status pics. No spaces in file names or it adds %20 for space in file name*************************************** //*****send Images to web page. Image files are stored on a Google nodemcuwebpics web site so only link is needed here.*****     client.println("
" // carriage return start new line    // client.println(""    // "
"    // "
"    "   "     "
"     "
"     "
"     "
"     "
"     "
"     "
"     "
"            "
"     "
"     "
"            "
"     "
"     "
");     //client.println("   "); // add space     //client.println("Inside Temp");     //client.println(t1,1); // print temp     //client.println("C"); // print temp     //client.println(" "); // add space     //client.println("RH"); // print temp     //client.println(h1,1); // print humidity     //client.println("%"); // print humidity %     //client.println(" ");     //client.println("Furnace LED: ");     //client.println(analoginput);     //client.println(" ");     //client.println(" Basement Temp ");     //client.println(temp1,1); //One decimal place     //client.println("C");     //client.println(" ");     //client.println(" Outside Temp ");     //client.println(temp2,1); //One decimal place     //client.println("C");     // Html sticks a space between println objects whether you want one or not. Create a single string to stop this.     client.println("       "); // add space     client.println("Inside Temp");     insidetemp = String(t1,1)+"C   ";     humidity = "RH "+String(h1,1)+"%   ";     furnaceLED = "Furnace LED "+String(analoginput)+"   ";     basementtemp = "Basement Temp "+String(temp1,1)+"C   ";     outsidetemp = "Outside Temp "+String(temp2,1)+"C";     tempdata = insidetemp + humidity + furnaceLED + basementtemp + outsidetemp;     client.println(tempdata);     client.println("
"     "
"     //***Furnace and water heater buttons***************     "            " //Clear Flag button definition. No spaces     "                 "     " "     //***End furnace and water heater buttons***********     "
"     "
");           //****Print furnace and water heater data     client.println("              OFF Flag");client.println(furnaceOFFflag);    client.println("   ");       if (furnaceONvalue >= 150) { client.println("Furnace:ON "); client.println(" ");}       if (furnaceONvalue < 150) client.println("Furnace:OFF");    client.println(" ");       if (furnacelo == 1) client.println("LO");       if (furnacelo == 0) client.println("HI");    client.println(" ");     client.println("Low SP"); client.println(lowsetpoint,1);    client.println(" ");       if (autowh == 1) client.println("Auto:ON ");       if (autowh == 0) client.println("Auto:OFF");     client.println(" ");       if (HeaterOFF == 1) client.println("Heater:OFF");       if (HeaterOFF == 0) client.println("Heater:ON");       client.println("
");          client.println("                                   ");      client.println("ON time");      StrfurnaceONtime = " " + String(furnaceONtime);     if (furnaceONtime < 10) StrfurnaceONtime = " " + StrfurnaceONtime;  // add leading spaces     if (furnaceONtime < 100) StrfurnaceONtime = " " + StrfurnaceONtime;      if (furnaceONtime < 1000) StrfurnaceONtime = " " + StrfurnaceONtime;     if (furnaceONtime < 10000) StrfurnaceONtime = " " + StrfurnaceONtime;     client.println(StrfurnaceONtime);     client.println("Rcrd");     StrfurnaceONrecord = String(furnaceONrecord);     if (furnaceONrecord < 10) StrfurnaceONrecord = " " + StrfurnaceONrecord;  // add leading spaces     if (furnaceONrecord < 100) StrfurnaceONrecord = " " + StrfurnaceONrecord;      if (furnaceONrecord < 1000) StrfurnaceONrecord = " " + StrfurnaceONrecord;     if (furnaceONrecord < 10000) StrfurnaceONrecord = " " + StrfurnaceONrecord;     client.println(StrfurnaceONrecord);          client.println("
");     client.println("                                   ");      client.println("OFF time");     StrfurnaceOFFtime = String(furnaceOFFtime);     if (furnaceOFFtime < 10) StrfurnaceOFFtime = " " + StrfurnaceOFFtime;  // add leading spaces     if (furnaceOFFtime < 100) StrfurnaceOFFtime = " " + StrfurnaceOFFtime;      if (furnaceOFFtime < 1000) StrfurnaceOFFtime = " " + StrfurnaceOFFtime;     if (furnaceOFFtime < 10000) StrfurnaceOFFtime = " " + StrfurnaceOFFtime;     client.println(StrfurnaceOFFtime);     client.println("Rcrd");     StrfurnaceOFFrecord = String(furnaceOFFrecord);     if (furnaceOFFrecord < 10) StrfurnaceOFFrecord = " " + StrfurnaceOFFrecord;  // add leading spaces     if (furnaceOFFrecord < 100) StrfurnaceOFFrecord = " " + StrfurnaceOFFrecord;      if (furnaceOFFrecord < 1000) StrfurnaceOFFrecord = " " + StrfurnaceOFFrecord;     if (furnaceOFFrecord < 10000) StrfurnaceOFFrecord = " " + StrfurnaceOFFrecord;     client.println(StrfurnaceOFFrecord);          client.println("
");     client.println("                                   ");      client.println("ON total");     StrONtotal = String(ONtotal);     if (ONtotal < 10) StrONtotal = " " + StrONtotal;  // add leading spaces     if (ONtotal < 100) StrONtotal = " " + StrONtotal;      if (ONtotal < 1000) StrONtotal = " " + StrONtotal;     if (ONtotal < 10000) StrONtotal = " " + StrONtotal;     client.println(StrONtotal);     client.println("ON%");     client.println(ONpercent);          client.println("
");     client.println("                                      ");      String heading = "Tm Total Hour";     heading = heading + " " + " " + " ";     heading = heading + "%";     client.println(heading);          client.println("
");     client.println("                                      ");      String StrONtotal0 = String(ONtotal0);     if (ONtotal0 < 10) StrONtotal0 = " " + StrONtotal0;  // add leading spaces     if (ONtotal0 < 100) StrONtotal0 = " " + StrONtotal0;      if (ONtotal0 < 1000) StrONtotal0 = " " + StrONtotal0;     if (ONtotal0 < 10000) StrONtotal0 = " " + StrONtotal0;     String StrONhour0 = String(ONhour0);     if (ONhour0 < 10) StrONhour0 = " " + StrONhour0;  // add leading spaces     if (ONhour0 < 100) StrONhour0 = " " + StrONhour0;      if (ONhour0 < 1000) StrONhour0 = " " + StrONhour0;     String StrONpct0 = String(ONpct0);     if (ONpct0 < 10) StrONpct0 = " " + StrONpct0;  // add leading spaces     if (ONpct0 < 100) StrONpct0 = " " + StrONpct0;  // add leading spaces     client.println("00");     client.println(StrONtotal0);     client.println(StrONhour0);     client.println(StrONpct0);      client.println("
");     client.println("                                      ");      String StrONtotal1 = String(ONtotal1);     if (ONtotal1 < 10) StrONtotal1 = " " + StrONtotal1;  // add leading spaces     if (ONtotal1 < 100) StrONtotal1 = " " + StrONtotal1;      if (ONtotal1 < 1000) StrONtotal1 = " " + StrONtotal1;     if (ONtotal1 < 10000) StrONtotal1 = " " + StrONtotal1;     String StrONhour1 = String(ONhour1);     if (ONhour1 < 10) StrONhour1 = " " + StrONhour1;  // add leading spaces     if (ONhour1 < 100) StrONhour1 = " " + StrONhour1;      if (ONhour1 < 1000) StrONhour1 = " " + StrONhour1;     String StrONpct1 = String(ONpct1);     if (ONpct1 < 10) StrONpct1 = " " + StrONpct1;  // add leading spaces     if (ONpct1 < 100) StrONpct1 = " " + StrONpct1;  // add leading spaces     client.println("01");     client.println(StrONtotal1);     client.println(StrONhour1);     client.println(StrONpct1);      client.println("
");     client.println("                                      ");      String StrONtotal2 = String(ONtotal2);     if (ONtotal2 < 10)    StrONtotal2 = " " + StrONtotal2;  // add leading spaces     if (ONtotal2 < 100)   StrONtotal2 = " " + StrONtotal2;      if (ONtotal2 < 1000)  StrONtotal2 = " " + StrONtotal2;     if (ONtotal2 < 10000) StrONtotal2 = " " + StrONtotal2;     String StrONhour2 = String(ONhour2);     if (ONhour2 < 10)   StrONhour2 = " " + StrONhour2;  // add leading spaces     if (ONhour2 < 100)  StrONhour2 = " " + StrONhour2;      if (ONhour2 < 1000) StrONhour2 = " " + StrONhour2;     String StrONpct2 = String(ONpct2);     if (ONpct2 < 10) StrONpct2 = " " + StrONpct2;  // add leading spaces     if (ONpct2 < 100) StrONpct2 = " " + StrONpct2;  // add leading spaces     client.println("02");     client.println(StrONtotal2);     client.println(StrONhour2);     client.println(StrONpct2); client.println("
");     client.println("                                      ");      String StrONtotal3 = String(ONtotal3);     if (ONtotal3 < 10)    StrONtotal3 = " " + StrONtotal3;  // add leading spaces     if (ONtotal3 < 100)   StrONtotal3 = " " + StrONtotal3;      if (ONtotal3 < 1000)  StrONtotal3 = " " + StrONtotal3;     if (ONtotal3 < 10000) StrONtotal3 = " " + StrONtotal3;     String StrONhour3 = String(ONhour3);     if (ONhour3 < 10)   StrONhour3 = " " + StrONhour3;  // add leading spaces     if (ONhour3 < 100)  StrONhour3 = " " + StrONhour3;      if (ONhour3 < 1000) StrONhour3 = " " + StrONhour3;     String StrONpct3 = String(ONpct3);     if (ONpct3 < 10) StrONpct3 = " " + StrONpct3;  // add leading spaces     if (ONpct3 < 100) StrONpct3 = " " + StrONpct3;  // add leading spaces     client.println("03");     client.println(StrONtotal3);     client.println(StrONhour3);     client.println(StrONpct3);     client.println("
");     client.println("                                      ");      String StrONtotal4 = String(ONtotal4);     if (ONtotal4 < 10)    StrONtotal4 = " " + StrONtotal4;  // add leading spaces     if (ONtotal4 < 100)   StrONtotal4 = " " + StrONtotal4;      if (ONtotal4 < 1000)  StrONtotal4 = " " + StrONtotal4;     if (ONtotal4 < 10000) StrONtotal4 = " " + StrONtotal4;     String StrONhour4 = String(ONhour4);     if (ONhour4 < 10)   StrONhour4 = " " + StrONhour4;  // add leading spaces     if (ONhour4 < 100)  StrONhour4 = " " + StrONhour4;      if (ONhour4 < 1000) StrONhour4 = " " + StrONhour4;     String StrONpct4 = String(ONpct4);     if (ONpct4 < 10) StrONpct4 = " " + StrONpct4;  // add leading spaces     if (ONpct4 < 100) StrONpct4 = " " + StrONpct4;  // add leading spaces     client.println("04");     client.println(StrONtotal4);     client.println(StrONhour4);     client.println(StrONpct4); client.println("
");     client.println("                                      ");      String StrONtotal5 = String(ONtotal5);     if (ONtotal5 < 10)    StrONtotal5 = " " + StrONtotal5;  // add leading spaces     if (ONtotal5 < 100)   StrONtotal5 = " " + StrONtotal5;      if (ONtotal5 < 1000)  StrONtotal5 = " " + StrONtotal5;     if (ONtotal5 < 10000) StrONtotal5 = " " + StrONtotal5;     String StrONhour5 = String(ONhour5);     if (ONhour5 < 10)   StrONhour5 = " " + StrONhour5;  // add leading spaces     if (ONhour5 < 100)  StrONhour5 = " " + StrONhour5;      if (ONhour5 < 1000) StrONhour5 = " " + StrONhour5;     String StrONpct5 = String(ONpct5);     if (ONpct5 < 10) StrONpct5 = " " + StrONpct5;  // add leading spaces     if (ONpct5 < 100) StrONpct5 = " " + StrONpct5;  // add leading spaces     client.println("05");     client.println(StrONtotal5);     client.println(StrONhour5);     client.println(StrONpct5); client.println("
");     client.println("                                      ");      String StrONtotal6 = String(ONtotal6);     if (ONtotal6 < 10)    StrONtotal6 = " " + StrONtotal6;  // add leading spaces     if (ONtotal6 < 100)   StrONtotal6 = " " + StrONtotal6;      if (ONtotal6 < 1000)  StrONtotal6 = " " + StrONtotal6;     if (ONtotal6 < 10000) StrONtotal6 = " " + StrONtotal6;     String StrONhour6 = String(ONhour6);     if (ONhour6 < 10)   StrONhour6 = " " + StrONhour6;  // add leading spaces     if (ONhour6 < 100)  StrONhour6 = " " + StrONhour6;      if (ONhour6 < 1000) StrONhour6 = " " + StrONhour6;     String StrONpct6 = String(ONpct6);     if (ONpct6 < 10) StrONpct6 = " " + StrONpct6;  // add leading spaces     if (ONpct6 < 100) StrONpct6 = " " + StrONpct6;  // add leading spaces     client.println("06");     client.println(StrONtotal6);     client.println(StrONhour6);     client.println(StrONpct6); client.println("
");     client.println("                                      ");      String StrONtotal7 = String(ONtotal7);     if (ONtotal7 < 10)    StrONtotal7 = " " + StrONtotal7;  // add leading spaces     if (ONtotal7 < 100)   StrONtotal7 = " " + StrONtotal7;      if (ONtotal7 < 1000)  StrONtotal7 = " " + StrONtotal7;     if (ONtotal7 < 10000) StrONtotal7 = " " + StrONtotal7;     String StrONhour7 = String(ONhour7);     if (ONhour7 < 10)   StrONhour7 = " " + StrONhour7;  // add leading spaces     if (ONhour7 < 100)  StrONhour7 = " " + StrONhour7;      if (ONhour7 < 1000) StrONhour7 = " " + StrONhour7;     String StrONpct7 = String(ONpct7);     if (ONpct7 < 10) StrONpct7 = " " + StrONpct7;  // add leading spaces     if (ONpct7 < 100) StrONpct7 = " " + StrONpct7;  // add leading spaces     client.println("07");     client.println(StrONtotal7);     client.println(StrONhour7);     client.println(StrONpct7); client.println("
");     client.println("                                      ");      String StrONtotal8 = String(ONtotal8);     if (ONtotal8 < 10)    StrONtotal8 = " " + StrONtotal8;  // add leading spaces     if (ONtotal8 < 100)   StrONtotal8 = " " + StrONtotal8;      if (ONtotal8 < 1000)  StrONtotal8 = " " + StrONtotal8;     if (ONtotal8 < 10000) StrONtotal8 = " " + StrONtotal8;     String StrONhour8 = String(ONhour8);     if (ONhour8 < 10)   StrONhour8 = " " + StrONhour8;  // add leading spaces     if (ONhour8 < 100)  StrONhour8 = " " + StrONhour8;      if (ONhour8 < 1000) StrONhour8 = " " + StrONhour8;     String StrONpct8 = String(ONpct8);     if (ONpct8 < 10) StrONpct8 = " " + StrONpct8;  // add leading spaces     if (ONpct8 < 100) StrONpct8 = " " + StrONpct8;  // add leading spaces     client.println("08");     client.println(StrONtotal8);     client.println(StrONhour8);     client.println(StrONpct8); client.println("
");     client.println("                                      ");      String StrONtotal9 = String(ONtotal9);     if (ONtotal9 < 10)    StrONtotal9 = " " + StrONtotal9;  // add leading spaces     if (ONtotal9 < 100)   StrONtotal9 = " " + StrONtotal9;      if (ONtotal9 < 1000)  StrONtotal9 = " " + StrONtotal9;     if (ONtotal9 < 10000) StrONtotal9 = " " + StrONtotal9;     String StrONhour9 = String(ONhour9);     if (ONhour9 < 10)   StrONhour9 = " " + StrONhour9;  // add leading spaces     if (ONhour9 < 100)  StrONhour9 = " " + StrONhour9;      if (ONhour9 < 1000) StrONhour9 = " " + StrONhour9;     String StrONpct9 = String(ONpct9);     if (ONpct9 < 10) StrONpct9 = " " + StrONpct9;  // add leading spaces     if (ONpct9 < 100) StrONpct9 = " " + StrONpct9;  // add leading spaces     client.println("09");     client.println(StrONtotal9);     client.println(StrONhour9);     client.println(StrONpct9); client.println("
");     client.println("                                      ");      String StrONtotal10 = String(ONtotal10);     if (ONtotal10 < 10)    StrONtotal10 = " " + StrONtotal10;  // add leading spaces     if (ONtotal10 < 100)   StrONtotal10 = " " + StrONtotal10;      if (ONtotal10 < 1000)  StrONtotal10 = " " + StrONtotal10;     if (ONtotal10 < 10000) StrONtotal10 = " " + StrONtotal10;     String StrONhour10 = String(ONhour10);     if (ONhour10 < 10)   StrONhour10 = " " + StrONhour10;  // add leading spaces     if (ONhour10 < 100)  StrONhour10 = " " + StrONhour10;      if (ONhour10 < 1000) StrONhour10 = " " + StrONhour10;     String StrONpct10 = String(ONpct10);     if (ONpct10 < 10) StrONpct10 = " " + StrONpct10;  // add leading spaces     if (ONpct10 < 100) StrONpct10 = " " + StrONpct10;  // add leading spaces     client.println("10");     client.println(StrONtotal10);     client.println(StrONhour10);     client.println(StrONpct10); client.println("
");     client.println("                                      ");      String StrONtotal11 = String(ONtotal11);     if (ONtotal11 < 10)    StrONtotal11 = " " + StrONtotal11;  // add leading spaces     if (ONtotal11 < 100)   StrONtotal11 = " " + StrONtotal11;      if (ONtotal11 < 1000)  StrONtotal11 = " " + StrONtotal11;     if (ONtotal11 < 10000) StrONtotal11 = " " + StrONtotal11;     String StrONhour11 = String(ONhour11);     if (ONhour11 < 10)   StrONhour11 = " " + StrONhour11;  // add leading spaces     if (ONhour11 < 100)  StrONhour11 = " " + StrONhour11;      if (ONhour11 < 1000) StrONhour11 = " " + StrONhour11;     String StrONpct11 = String(ONpct11);     if (ONpct11 < 10) StrONpct11 = " " + StrONpct11;  // add leading spaces     if (ONpct11 < 100) StrONpct11 = " " + StrONpct11;  // add leading spaces     client.println("11");     client.println(StrONtotal11);     client.println(StrONhour11);     client.println(StrONpct11); client.println("
");     client.println("                                      ");      String StrONtotal12 = String(ONtotal12);     if (ONtotal12 < 10)    StrONtotal12 = " " + StrONtotal12;  // add leading spaces     if (ONtotal12 < 100)   StrONtotal12 = " " + StrONtotal12;      if (ONtotal12 < 1000)  StrONtotal12 = " " + StrONtotal12;     if (ONtotal12 < 10000) StrONtotal12 = " " + StrONtotal12;     String StrONhour12 = String(ONhour12);     if (ONhour12 < 10)   StrONhour12 = " " + StrONhour12;  // add leading spaces     if (ONhour12 < 100)  StrONhour12 = " " + StrONhour12;      if (ONhour12 < 1000) StrONhour12 = " " + StrONhour12;     String StrONpct12 = String(ONpct12);     if (ONpct12 < 10) StrONpct12 = " " + StrONpct12;  // add leading spaces     if (ONpct12 < 100) StrONpct12 = " " + StrONpct12;  // add leading spaces     client.println("12");     client.println(StrONtotal12);     client.println(StrONhour12);     client.println(StrONpct12); client.println("
");     client.println("                                      ");      String StrONtotal13 = String(ONtotal13);     if (ONtotal13 < 10)    StrONtotal13 = " " + StrONtotal13;  // add leading spaces     if (ONtotal13 < 100)   StrONtotal13 = " " + StrONtotal13;      if (ONtotal13 < 1000)  StrONtotal13 = " " + StrONtotal13;     if (ONtotal13 < 10000) StrONtotal13 = " " + StrONtotal13;     String StrONhour13 = String(ONhour13);     if (ONhour13 < 10)   StrONhour13 = " " + StrONhour13;  // add leading spaces     if (ONhour13 < 100)  StrONhour13 = " " + StrONhour13;      if (ONhour13 < 1000) StrONhour13 = " " + StrONhour13;     String StrONpct13 = String(ONpct13);     if (ONpct13 < 10) StrONpct13 = " " + StrONpct13;  // add leading spaces     if (ONpct13 < 100) StrONpct13 = " " + StrONpct13;  // add leading spaces     client.println("13");     client.println(StrONtotal13);     client.println(StrONhour13);     client.println(StrONpct13);   client.println("
");     client.println("                                      ");      String StrONtotal14 = String(ONtotal14);     if (ONtotal14 < 10)    StrONtotal14 = " " + StrONtotal14;  // add leading spaces     if (ONtotal14 < 100)   StrONtotal14 = " " + StrONtotal14;      if (ONtotal14 < 1000)  StrONtotal14 = " " + StrONtotal14;     if (ONtotal14 < 10000) StrONtotal14 = " " + StrONtotal14;     String StrONhour14 = String(ONhour14);     if (ONhour14 < 10)   StrONhour14 = " " + StrONhour14;  // add leading spaces     if (ONhour14 < 100)  StrONhour14 = " " + StrONhour14;      if (ONhour14 < 1000) StrONhour14 = " " + StrONhour14;     String StrONpct14 = String(ONpct14);     if (ONpct14 < 10) StrONpct14 = " " + StrONpct14;  // add leading spaces     if (ONpct14 < 100) StrONpct14 = " " + StrONpct14;  // add leading spaces     client.println("14");     client.println(StrONtotal14);     client.println(StrONhour14);     client.println(StrONpct14); client.println("
");     client.println("                                      ");      String StrONtotal15 = String(ONtotal15);     if (ONtotal15 < 10)    StrONtotal15 = " " + StrONtotal15;  // add leading spaces     if (ONtotal15 < 100)   StrONtotal15 = " " + StrONtotal15;      if (ONtotal15 < 1000)  StrONtotal15 = " " + StrONtotal15;     if (ONtotal15 < 10000) StrONtotal15 = " " + StrONtotal15;     String StrONhour15 = String(ONhour15);     if (ONhour15 < 10)   StrONhour15 = " " + StrONhour15;  // add leading spaces     if (ONhour15 < 100)  StrONhour15 = " " + StrONhour15;      if (ONhour15 < 1000) StrONhour15 = " " + StrONhour15;     String StrONpct15 = String(ONpct15);     if (ONpct15 < 10) StrONpct15 = " " + StrONpct15;  // add leading spaces     if (ONpct15 < 100) StrONpct15 = " " + StrONpct15;  // add leading spaces     client.println("15");     client.println(StrONtotal15);     client.println(StrONhour15);     client.println(StrONpct15); client.println("
");     client.println("                                      ");      String StrONtotal16 = String(ONtotal16);     if (ONtotal16 < 10)    StrONtotal16 = " " + StrONtotal16;  // add leading spaces     if (ONtotal16 < 100)   StrONtotal16 = " " + StrONtotal16;      if (ONtotal16 < 1000)  StrONtotal16 = " " + StrONtotal16;     if (ONtotal16 < 10000) StrONtotal16 = " " + StrONtotal16;     String StrONhour16 = String(ONhour16);     if (ONhour16 < 10)   StrONhour16 = " " + StrONhour16;  // add leading spaces     if (ONhour16 < 100)  StrONhour16 = " " + StrONhour16;      if (ONhour16 < 1000) StrONhour16 = " " + StrONhour16;     String StrONpct16 = String(ONpct16);     if (ONpct16 < 10) StrONpct16 = " " + StrONpct16;  // add leading spaces     if (ONpct16 < 100) StrONpct16 = " " + StrONpct16;  // add leading spaces     client.println("16");     client.println(StrONtotal16);     client.println(StrONhour16);     client.println(StrONpct16); client.println("
");     client.println("                                      ");      String StrONtotal17 = String(ONtotal17);     if (ONtotal17 < 10)    StrONtotal17 = " " + StrONtotal17;  // add leading spaces     if (ONtotal17 < 100)   StrONtotal17 = " " + StrONtotal17;      if (ONtotal17 < 1000)  StrONtotal17 = " " + StrONtotal17;     if (ONtotal17 < 10000) StrONtotal17 = " " + StrONtotal17;     String StrONhour17 = String(ONhour17);     if (ONhour17 < 10)   StrONhour17 = " " + StrONhour17;  // add leading spaces     if (ONhour17 < 100)  StrONhour17 = " " + StrONhour17;      if (ONhour17 < 1000) StrONhour17 = " " + StrONhour17;     String StrONpct17 = String(ONpct17);     if (ONpct17 < 10) StrONpct17 = " " + StrONpct17;  // add leading spaces     if (ONpct17 < 100) StrONpct17 = " " + StrONpct17;  // add leading spaces     client.println("17");     client.println(StrONtotal17);     client.println(StrONhour17);     client.println(StrONpct17); client.println("
");     client.println("                                      ");      String StrONtotal18 = String(ONtotal18);     if (ONtotal18 < 10)    StrONtotal18 = " " + StrONtotal18;  // add leading spaces     if (ONtotal18 < 100)   StrONtotal18 = " " + StrONtotal18;      if (ONtotal18 < 1000)  StrONtotal18 = " " + StrONtotal18;     if (ONtotal18 < 10000) StrONtotal18 = " " + StrONtotal18;     String StrONhour18 = String(ONhour18);     if (ONhour18 < 10)   StrONhour18 = " " + StrONhour18;  // add leading spaces     if (ONhour18 < 100)  StrONhour18 = " " + StrONhour18;      if (ONhour18 < 1000) StrONhour18 = " " + StrONhour18;     String StrONpct18 = String(ONpct18);     if (ONpct18 < 10) StrONpct18 = " " + StrONpct18;  // add leading spaces     if (ONpct18 < 100) StrONpct18 = " " + StrONpct18;  // add leading spaces     client.println("18");     client.println(StrONtotal18);     client.println(StrONhour18);     client.println(StrONpct18); client.println("
");     client.println("                                      ");      String StrONtotal19 = String(ONtotal19);     if (ONtotal19 < 10)    StrONtotal19 = " " + StrONtotal19;  // add leading spaces     if (ONtotal19 < 100)   StrONtotal19 = " " + StrONtotal19;      if (ONtotal19 < 1000)  StrONtotal19 = " " + StrONtotal19;     if (ONtotal19 < 10000) StrONtotal19 = " " + StrONtotal19;     String StrONhour19 = String(ONhour19);     if (ONhour19 < 10)   StrONhour19 = " " + StrONhour19;  // add leading spaces     if (ONhour19 < 100)  StrONhour19 = " " + StrONhour19;      if (ONhour19 < 1000) StrONhour19 = " " + StrONhour19;     String StrONpct19 = String(ONpct19);     if (ONpct19 < 10) StrONpct19 = " " + StrONpct19;  // add leading spaces     if (ONpct19 < 100) StrONpct19 = " " + StrONpct19;  // add leading spaces     client.println("19");     client.println(StrONtotal19);     client.println(StrONhour19);     client.println(StrONpct19); client.println("
");     client.println("                                      ");      String StrONtotal20 = String(ONtotal20);     if (ONtotal20 < 10)    StrONtotal20 = " " + StrONtotal20;  // add leading spaces     if (ONtotal20 < 100)   StrONtotal20 = " " + StrONtotal20;      if (ONtotal20 < 1000)  StrONtotal20 = " " + StrONtotal20;     if (ONtotal20 < 10000) StrONtotal20 = " " + StrONtotal20;     String StrONhour20 = String(ONhour20);     if (ONhour20 < 10)   StrONhour20 = " " + StrONhour20;  // add leading spaces     if (ONhour20 < 100)  StrONhour20 = " " + StrONhour20;      if (ONhour20 < 1000) StrONhour20 = " " + StrONhour20;     String StrONpct20 = String(ONpct20);     if (ONpct20 < 10) StrONpct20 = " " + StrONpct20;  // add leading spaces     if (ONpct20 < 100) StrONpct20 = " " + StrONpct20;  // add leading spaces     client.println("20");     client.println(StrONtotal20);     client.println(StrONhour20);     client.println(StrONpct20); client.println("
");     client.println("                                      ");      String StrONtotal21 = String(ONtotal21);     if (ONtotal21 < 10)    StrONtotal21 = " " + StrONtotal21;  // add leading spaces     if (ONtotal21 < 100)   StrONtotal21 = " " + StrONtotal21;      if (ONtotal21 < 1000)  StrONtotal21 = " " + StrONtotal21;     if (ONtotal21 < 10000) StrONtotal21 = " " + StrONtotal21;     String StrONhour21 = String(ONhour21);     if (ONhour21 < 10)   StrONhour21 = " " + StrONhour21;  // add leading spaces     if (ONhour21 < 100)  StrONhour21 = " " + StrONhour21;      if (ONhour21 < 1000) StrONhour21 = " " + StrONhour21;     String StrONpct21 = String(ONpct21);     if (ONpct21 < 10) StrONpct21 = " " + StrONpct21;  // add leading spaces     if (ONpct21 < 100) StrONpct21 = " " + StrONpct21;  // add leading spaces     client.println("21");     client.println(StrONtotal21);     client.println(StrONhour21);     client.println(StrONpct21); client.println("
");     client.println("                                      ");      String StrONtotal22 = String(ONtotal22);     if (ONtotal22 < 10)    StrONtotal22 = " " + StrONtotal22;  // add leading spaces     if (ONtotal22 < 100)   StrONtotal22 = " " + StrONtotal22;      if (ONtotal22 < 1000)  StrONtotal22 = " " + StrONtotal22;     if (ONtotal22 < 10000) StrONtotal22 = " " + StrONtotal22;     String StrONhour22 = String(ONhour22);     if (ONhour22 < 10)   StrONhour22 = " " + StrONhour22;  // add leading spaces     if (ONhour22 < 100)  StrONhour22 = " " + StrONhour22;      if (ONhour22 < 1000) StrONhour22 = " " + StrONhour22;     String StrONpct22 = String(ONpct22);     if (ONpct22 < 10) StrONpct22 = " " + StrONpct22;  // add leading spaces     if (ONpct22 < 100) StrONpct22 = " " + StrONpct22;  // add leading spaces     client.println("22");     client.println(StrONtotal22);     client.println(StrONhour22);     client.println(StrONpct22); client.println("
");     client.println("                                      ");      String StrONtotal23 = String(ONtotal23);     if (ONtotal23 < 10)    StrONtotal23 = " " + StrONtotal23;  // add leading spaces     if (ONtotal23 < 100)   StrONtotal23 = " " + StrONtotal23;      if (ONtotal23 < 1000)  StrONtotal23 = " " + StrONtotal23;     if (ONtotal23 < 10000) StrONtotal23 = " " + StrONtotal23;     String StrONhour23 = String(ONhour23);     if (ONhour23 < 10)   StrONhour23 = " " + StrONhour23;  // add leading spaces     if (ONhour23 < 100)  StrONhour23 = " " + StrONhour23;      if (ONhour23 < 1000) StrONhour23 = " " + StrONhour23;     String StrONpct23 = String(ONpct23);     if (ONpct23 < 10) StrONpct23 = " " + StrONpct23;  // add leading spaces     if (ONpct23 < 100) StrONpct23 = " " + StrONpct23;  // add leading spaces     client.println("23");     client.println(StrONtotal23);     client.println(StrONhour23);     client.println(StrONpct23);     // client.println(counter);            client.println("
"      "
"      "
"      "
"      "
"      "
"      "
"      "
"      "
"      "
"      "
"      "
"      "
"      "
"      "
"      "
"      "
"      "
"      "
"      "
"      "
"      "
"      "
"      "
"      "
"      "
"      "
"                 "." // add period below the background you want to display or it won't scroll past last text     "

"       "");    client.println("
"); client.println("");  client.stop(); // disconnect client to allow other clients   delay(1);      //****************************************** }